package com.atung.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atung.response.ResponseChangeSchool;
import com.atung.response.ResponsePagePath;
import com.atung.service.BusProvinceCityService;
import com.atung.service.SchoolPageService;
import com.github.pagehelper.PageHelper;
import com.yuyi.full.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/wxPage")
@Api(tags="微信首页")
public class PageController {

	@Autowired
	private SchoolPageService schoolPageService;
	@Autowired
	private BusProvinceCityService busProvinceCityService;
	
	
	@GetMapping("/getSchool")
	@ApiOperation("/获取我的学校")
	public Result<?>getSchool(@RequestParam String openId) {
		ResponseChangeSchool result;
		try {
			result = schoolPageService.selectSchoolNameByOpenId(openId);
			return Result.success(result);
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			return Result.error(100, e.getMessage());
		}
		
	}
	
	
	@GetMapping("/changeSchool")
	@ApiOperation("/切换学校")
	public Result<List<ResponseChangeSchool>>changeSchoolList(@RequestParam(required=false) String schoolName){	
		return Result.success(schoolPageService.selectSchoolNameAll(schoolName));
	}
	
	@GetMapping("/getProvince")
	@ApiOperation("查看省")
	public Result<String>selecyBusProvinceProvince(){
		List<String>ProvinceList=busProvinceCityService.selecyBusProvinceProvince();
		return Result.success(ProvinceList);
	}
	
	@GetMapping("/getInquire")
	@ApiOperation("/搜素获取行程列表")
	public Result<List<ResponsePagePath>>getInquire(@RequestParam String openId,
									@RequestParam Long schoolId,
									@RequestParam List<String> destination,
									@RequestParam(required=false,defaultValue="0") Integer pageNum,
									@RequestParam(required=false,defaultValue="10") Integer pageSize)throws Exception{
		
		if(destination.size()!=2){
			throw new Exception("请选择城市");
		}
		List<ResponsePagePath> result=schoolPageService.selectSchoolNameAndCity(openId,schoolId,destination);
		return Result.success(result);
	}
		
	@GetMapping("/homecoming")
	@ApiOperation("/返校路线查询")
	public Result<List<ResponsePagePath>>homecoming(@RequestParam String openId,
									@RequestParam Long schoolId,
									@RequestParam List<String> destination,
									@RequestParam(required=false,defaultValue="0") Integer pageNum,
									@RequestParam(required=false,defaultValue="10") Integer pageSize)throws Exception{
		
		if(destination.size()!=2){
			throw new Exception("请选择城市");
		}
		List<ResponsePagePath> result=schoolPageService.selectCityAndSchoolName(openId,schoolId,destination);
		return Result.success(result);
	}
	

//	@GetMapping("/pathRecommend")
//	@ApiOperation("推荐路线")
//	public Result<List<ResponsePagePath>>pathRecommend(@RequestParam String openId,
//			@RequestParam(required=false,defaultValue="0") Integer pageNum,
//			@RequestParam(required=false,defaultValue="10") Integer pageSize){
//		/**
//		 * 根据当前学校查询是否有开通路线 
//		 * 没有 根据附近学校查询全部路线
//		 */
//		PageHelper.startPage(pageNum, pageSize);
//		PageInfo<ResponsePagePath>pi=new PageInfo<>();
//		return Result.success(pi);
//	}
//	

}
